package com.zhuang.jdk8.lambda;

import java.util.Arrays;
import java.util.Comparator;

public class PersonTest {
	public static void main(String[] args) {
		Person[] persons = new Person[4];
		persons[0] = new Person("张三", 25);
		persons[1] = new Person("李四", 30);
		persons[2] = new Person("王五", 46);
		persons[3] = new Person("赵六", 89);
		System.out.println("-----------Comparator接口-----------");
		Arrays.sort(persons, (a, b) -> a.getAge() - b.getAge());
		for (Person person : persons) {
			System.out.println(person);
		}

		System.out.println("-----------Comparator接口lambda接口-----------");
		Arrays.sort(persons, new Comparator<Person>() {
			public int compare(Person o1, Person o2) {
				return o1.getAge() - o2.getAge();
			};
		});
		for (Person person : persons) {
			System.out.println(person);
		}
	}
}
